package com.paul.security;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by dell on 2016/3/23.
 */
public class RedisShiroCache implements CacheManager {

    private static Logger logger = LoggerFactory.getLogger(RedisSessionDAO.class);
    private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap();

    @Autowired
    private RedisCache redisCache;

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        logger.debug("获取shirocache实例:"+name);
        Cache c = caches.get(name);
        if(c==null){
            c=redisCache;
        }
        return c;
    }

}
